const app = getApp();
const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    
    searchForm: {
      pageNumber: 1, // 当前页数
      pageSize: 10, // 页面大小
      sort: 'timeEnd',
      order: 'desc',
    },
    totalPages: 0,
    loading: false, //是否正在加载数据
    list: [],
    collectData: [],//收藏的展商id数组

  },
  //当前页发生改变
  changePage(v) {
    this.setData({
      'searchForm.pageNumber': v
    });
    this.getVoteData();
  },
  //查询方法
  handleSearch() {
    this.setData({
      'searchForm.pageNumber': 1
    });
    this.getVoteData();
  },
  //获取投票活动数据
  getVoteData: function () {
    let that = this;
    that.setData({
      loading: true
    })
    //加载信息
    util.request(api.VOTE_LIST, that.data.searchForm).then(function (res) {
      if (res.success === true) {
        let data = new Object();
        let list = [];
        if (that.data.searchForm.pageNumber > 1) { //加载更多  追加信息
          list = that.data.list;
        }
        list.push(...res.result.content)
        data.list = list;
        data.totalPages = res.result.totalPages;
        data.loading = false;
        that.setData(data);
      }
    });

  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //加载
    this.getVoteData();
  },
  //明细页面
  goItem(e) {
    let voteId = e.currentTarget.dataset.id;
    let voteName = e.currentTarget.dataset.votename;
    let voteDate = e.currentTarget.dataset.votedate;
    wx.navigateTo({
      url: `/pages/vote/vote-item-list/index?voteId=${voteId}&voteName=${voteName}&voteDate=${voteDate}`,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.changePage(++this.data.searchForm.pageNumber);
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})